home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1993 / Internet Info CD-ROM (Walnut Creek) (1993).iso / networking / ip / sized_io.shar / writer-auto.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-29  |  1.2 KB  |  64 lines

  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <sys/time.h>
  4. #include <sys/socket.h>
  5. #include <netinet/in.h>
  6. /* #include <netdb.h> */
  7. #include "inet.h"
  8.  
  9. #define MAXBUFSIZ 500000
  10.  
  11. char msg[MAXBUFSIZ];
  12.  
  13. struct timeval timeout = {0L, 0L};
  14. int maxfds;
  15.  
  16. main(argc,argv)
  17. int argc;
  18. char **argv;
  19. {
  20.     extern char *optarg;
  21.     int c, debugLevel = 0;
  22.     char *host = 0;
  23.  
  24.     int cc;
  25.     int i;
  26.     int fd;
  27.     fd_set readfds;
  28.     FD_ZERO(&readfds);
  29.  
  30.     while ((c = getopt(argc,argv,"h:")) != EOF) {
  31.         switch (c) {
  32.         case 'h': host = optarg; break;
  33.         default: exit(-1);
  34.         }
  35.     }
  36.  
  37.     maxfds = getdtablesize();
  38.         /* prevent narrow fd_set binaries from blowing up with with */
  39.     /* large getdtablesize() */
  40. #ifdef FD_SET_SIZE
  41.     maxfds = ((FD_SET_SIZE > maxfds)?maxfds:FD_SET_SIZE);
  42. #endif
  43.  
  44.     fd = initport(PORT_NUMBER(2000),CLIENT,SOCK_STREAM,host);
  45.  
  46.     if (fd < 0) {
  47.         fprintf(stderr,"initport() = %d\n",fd);
  48.         exit(-1);
  49.     }
  50.     for (i=1;i<MAXBUFSIZ;i *= 2) {
  51.         printf("writing %d chars\n",i);
  52. /*        cc = sized_write(fd,msg,i);*/
  53.         cc = send(fd,msg,i,0);
  54.         FD_SET(fd,&readfds);
  55.         if (0 < select(maxfds,&readfds,0,0,&timeout)
  56.            && FD_ISSET(fd,&readfds)) {
  57. /*            cc = sized_read(fd,msg,MAXBUFSIZ);*/
  58.             cc = recv(fd,msg,MAXBUFSIZ,0);
  59.             msg[cc] = '\0';
  60.             printf("msg from server: %s\n",msg);
  61.         }
  62.     }
  63. }
  64.